package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("admin/product")
public class SpuManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 根据查询条件封装控制器
     * springMVC 的时候，有个叫对象属性传值 如果页面提交过来的参数与实体类的参数一致
     * 则可以使用实体类来接收数据
     */
    @GetMapping("{page}/{size}")
    public Result getSpuInfoPage(@PathVariable("page") Long page, @PathVariable("size") Long size, SpuInfo spuInfo) {
        return Result.ok(manageService.getSpuInfoPage(page, size, spuInfo));
    }


    @GetMapping("baseSaleAttrList")
    public Result getBaseSaleAttrList() {
        //查询所有属性值
        List<BaseSaleAttr> baseSaleAttrs = manageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrs);
    }


    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }






}
